using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class SalesmanMap : EntityTypeConfiguration<Salesman>
    {
        public SalesmanMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.SALESMAN1)
                .IsRequired()
                .HasMaxLength(30);

            this.Property(t => t.REGION)
                .HasMaxLength(5);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            this.Property(t => t.Symbol)
                .HasMaxLength(2);

            this.Property(t => t.SL_Email)
                .HasMaxLength(50);

            this.Property(t => t.SL_HomePhone)
                .HasMaxLength(50);

            this.Property(t => t.SL_BusinessPhone)
                .HasMaxLength(50);

            this.Property(t => t.SL_Mobile)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Salesmen");
            this.Property(t => t.SALESMAN1).HasColumnName("SALESMAN");
            this.Property(t => t.REGION).HasColumnName("REGION");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.Symbol).HasColumnName("Symbol");
            this.Property(t => t.SL_Gender).HasColumnName("SL_Gender");
            this.Property(t => t.SL_BirthDate).HasColumnName("SL_BirthDate");
            this.Property(t => t.SL_Nationality).HasColumnName("SL_Nationality");
            this.Property(t => t.SL_Email).HasColumnName("SL_Email");
            this.Property(t => t.SL_HomePhone).HasColumnName("SL_HomePhone");
            this.Property(t => t.SL_BusinessPhone).HasColumnName("SL_BusinessPhone");
            this.Property(t => t.SL_Mobile).HasColumnName("SL_Mobile");
            this.Property(t => t.SL_User).HasColumnName("SL_User");
            this.Property(t => t.SL_Notes).HasColumnName("SL_Notes");
            this.Property(t => t.SL_CreatedBy).HasColumnName("SL_CreatedBy");
            this.Property(t => t.SL_CreatedOn).HasColumnName("SL_CreatedOn");
            this.Property(t => t.SL_Photo).HasColumnName("SL_Photo");
            this.Property(t => t.SL_Inactive).HasColumnName("SL_Inactive");
            this.Property(t => t.SL_ID2).HasColumnName("SL_ID2");

            // Relationships
            this.HasOptional(t => t.Country)
                .WithMany(t => t.Salesmen)
                .HasForeignKey(d => d.SL_Nationality);
            this.HasOptional(t => t.Name)
                .WithMany(t => t.Salesmen)
                .HasForeignKey(d => d.SL_CreatedBy);

        }
    }
}
